//
//  SegmentedCollectionView.swift
//  PageNavigator
//
//  Created by 张奇 on 2025/8/14.
//

import UIKit

class SegmentedCollectionView: UICollectionView {

    var indicators = [SegmentIndicatorProtocol]() {
        willSet {
            for indicator in indicators {
                indicator.removeFromSuperview()
            }
        }
        didSet {
            for indicator in indicators {
                addSubview(indicator)
            }
        }
    }
    
    func addIndicator(_ indicator: SegmentIndicatorProtocol) {
        indicators.append(indicator)
        addSubview(indicator)
    }

    override func layoutSubviews() {
        super.layoutSubviews()

        for indicator in indicators {
            sendSubview(toBack: indicator)
            if let backgroundView = backgroundView {
                sendSubview(toBack: backgroundView)
            }
        }
    }

}
